package controller.listeners.manualCode;



import model.ManualCodeModel;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import business.database.filtersemantic.CorpsFilterEnum;


import view.ManualCodeView;

/**
 * Controlador para el boton de busqueda en el fitro
 * @author 53385255R
 *
 */
public class FilterSearchListener extends SelectionAdapter {

	private ManualCodeModel _model;
	private ManualCodeView _view;
	
	/**
	 * Constructor
	 * @param view
	 * @param model
	 */
	public FilterSearchListener(ManualCodeView view, ManualCodeModel model) {
		this._model = model;
		this._view = view;
	}
	
	/**
	 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
	 */
	@Override
	public void widgetSelected(SelectionEvent event) {

		
		int minid = _model.getMinIdCodeCorp();
	 	int maxid = _model.getMaxIdCodeCorp();
		 _model.reset();
		 
		
		 CorpsFilterEnum filterEnum = _view.getFilterCombo();
	 	 _model.setCorpFilter(_view.getCorpFilter(),_view.getProvCombo(), _view.getProvFilter(),_view.getInstitCombo(),_view.getInstitFilter(), _view.getOrgCombo(), _view.getOrgFilter(),
	 			 _view.getDptoCombo(), _view.getDptoFilter(),_view.getSectorCombo(), _view.getSectorFilter(), filterEnum, minid,maxid);
	 	 
	 	 _model.set_custom_corp("");
	 	 
	 	 _view.setCachePreCodeCorps(_model.get_cache_precodecorps());
	 	 
	 	 _view.setCandidateCenters(_model.getCandidateCenters(), _view.getSelected_cache_code_corp());
		
	}
}
